//
//  UITableView+EmptyData.m
//  SISSAPP
//
//  Created by 优房网 on 2017/4/11.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "UITableView+EmptyData.h"

@implementation UITableView (EmptyData)

- (void)tableViewDisplayWithMessage:(NSString *)message ifNecessaryForRowCount:(NSUInteger)rowCount {
    
    if (rowCount == 0) {
        // Display a message when the table is empty
        UIView *bgView = [[UIView alloc] init];
        
        NSString *imageName = [SISSPublicSingleton shared].isNoNetwork ? @"网络" : @"空白";
        NSString *textStr = [SISSPublicSingleton shared].isNoNetwork ? @"糟糕~网络开小差了" : message;
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
        [bgImageView sizeToFit];
        [bgView addSubview:bgImageView];
        
        UILabel *tipLabel = [[UILabel alloc] init];
        tipLabel.font = [UIFont systemFontOfSize:12];
        tipLabel.textColor = COLOR(0x8998A5);
        tipLabel.text = textStr;
        [bgView addSubview:tipLabel];
        
        [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(bgView);
            make.centerY.equalTo(bgView).offset(- 44);
        }];
        
        [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bgImageView.mas_bottom).offset(16);
            make.centerX.equalTo(bgView);
        }];
        
        
        self.backgroundView = bgView;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
    } else {
        self.backgroundView = nil;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
    }

}

@end
